/*
 * Copyright (C), 2014-2015, 联创车盟汽车服务有限公司
 * FileName: SpecialBookService.java
 * Author:   Freeman
 * Date:     2015年1月29日 下午5:15:30
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>    <time>    <version>    <desc>
 * 修改人姓名        修改时间        版本号        描述
 */
package com.linkage.service.commodity;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.linkage.pojo.commodity.SpecialBook;
import com.linkage.repository.commodity.SpecialBookRepository;
import com.linkage.service.background.BookManageService;

/**
 * 〈一句话功能简述〉<br> 
 * 特价书的service模块
 * 〈功能详细描述〉
 *
 * @author Freeman
 *
 */
@Service
public class SpecialBookService {
    @Autowired
    private SpecialBookRepository specialBookRepository;
    @Autowired
    private BookManageService bookManageService;
    //列出特价书籍            过时
    public List<SpecialBook> listSpecialBooks(){
        List<SpecialBook> specialbook=this.specialBookRepository.select();
        return specialbook;
    }
    
    //列出 级联了book表的特价书籍表
    public List<Map<String, Object>> listBookSpecial(){
        return this.bookManageService.listSpecialList();
    }
    
    public void delete(Integer specialId){
        this.specialBookRepository.delete(specialId);
    }
    
    public void save(SpecialBook sb){
        this.specialBookRepository.save(sb);
    }
    
    public boolean createSpecialBook(HttpServletRequest request, Integer bookId,Float specialPrice){
        String temp=""+specialPrice;
        try{
            Float.parseFloat(temp);
            }catch(NumberFormatException e){
                return false;
            }
        SpecialBook sb=new SpecialBook();
        sb.setBookId(bookId);
        sb.setSpecialPrice(specialPrice);
        this.save(sb);
        return true;
    }
}
